﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Presenters.General_Presenters;
using Interfaces.General_Interfaces;
using Interfaces.Add_Interfaces;
using Model.Domain_Model;
using Views.Add_Views;
using Views.Status_Views;

namespace Views
{
    public partial class SearchClientView : Form, ISearchClientView
    {
        SearchClientPresenter presenter = null;

        public SearchClientView()
        {
            InitializeComponent();
            presenter = new SearchClientPresenter(this);
        }

        Client ISearchClientView.client
        {
            get
            {
                return presenter.selectedClient;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        void Interfaces.Inherited_Interfaces.IError.ShowError()
        {
            presenter.ShowError(new ErrorView());
        }

        void Interfaces.Inherited_Interfaces.ISuccess.ShowSuccess()
        {
            throw new NotImplementedException();
        }

        void IParamable.SetParams(params object[] param)
        {
            presenter.roadView = (RoadNewView)param.Where(x => x.GetType() == typeof(RoadNewView)).FirstOrDefault();
        }

        T Interfaces.Inherited_Interfaces.IView.ReturnView<T>()
        {
            return (T)((object)this);
        }


        System.Collections.Generic.IList<Client> ISearchClientView.clientList
        {
            get
            {
                return (List<Client>)dataGridView1.DataSource;
            }
            set
            {
                dataGridView1.DataSource = value as List<Client>;
            }
        }

        string ISearchClientView.nameCorporation
        {
            get
            {
                return nameCorporation.Text;
            }
            set
            {
                nameCorporation.Text = value as string;
            }
        }

        private void label5_Click(object sender, EventArgs e)
        {
            presenter.Search();
        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            presenter.ExitApp();
        }

        void Interfaces.Inherited_Interfaces.ICloseable.Close()
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            presenter.Choose();
        }


        string ISearchClientView.inventedName
        {
            get
            {
                return inventedName.Text;
            }
            set
            {
                inventedName.Text = value as string;
            }
        }

        string ISearchClientView.nameClient
        {
            get
            {
                return nameClient.Text;
            }
            set
            {
                nameClient.Text = value as string;
            }
        }

        string ISearchClientView.surnameClient
        {
            get
            {
                return surnameClient.Text;
            }
            set
            {
                surnameClient.Text = value as string;
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            presenter.selectedClient = (Client)dataGridView1.CurrentRow.DataBoundItem;
        }

        void Interfaces.Inherited_Interfaces.IGrid.HideColumn()
        {
            dataGridView1.Columns["descriptionClient"].Visible = false;
            dataGridView1.Columns["isProtected"].Visible = false;
            dataGridView1.Columns["dateInsert"].Visible = false;
        }

        void Interfaces.Inherited_Interfaces.IGrid.MappingColumnName()
        {
            dataGridView1.Columns["nameCorporation"].HeaderCell.Value = "Firma";
            dataGridView1.Columns["nameClient"].HeaderCell.Value = "Imię klienta";
            dataGridView1.Columns["surnameClient"].HeaderCell.Value = "Nazwisko klienta";
            dataGridView1.Columns["inventedName"].HeaderCell.Value = "Nazwa własna";
            dataGridView1.Columns["email"].HeaderCell.Value = "E-mail";
            dataGridView1.Columns["phoneNumber"].HeaderCell.Value = "Numer telefonu";
            dataGridView1.Columns["idClient"].HeaderCell.Value = "Id";
        }

        void Interfaces.Inherited_Interfaces.IGrid.ResizeColumn()
        {
            dataGridView1.Columns["idClient"].Width = 70;
            dataGridView1.Columns["email"].Width = 200;
            dataGridView1.Columns["phoneNumber"].Width = 130;
            dataGridView1.Columns["nameClient"].Width = 130;
            dataGridView1.Columns["surnameClient"].Width = 140;
            dataGridView1.Columns["inventedName"].Width = 120;
        }
    }
}
